//
//  EvaluateListService.m
//  homeland
//
//  Created by caesar on 14-8-5.
//  Copyright (c) 2014年 xzysun. All rights reserved.
//

#import "EvaluateListService.h"

@implementation EvaluateListService
//请求参数集


- (void)loadDataWithKey:(NSString *)keyOrNil{
    _currentPageNo = 1;
    if (self.dataList) {
        self.dataList = nil;
    }
    //  
    _dataItemName = @"EvaluateEntity";
    NSDictionary *_config = [super paramDic];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:[CommonUtil formatDateStrStyle:@"yyyyMM"] forKey:@"yearWeek"];
    [params setValue:[_config objectForKey:@"uid"] forKey:@"uid"];
    [params setValue:@"" forKey:@"userId"];
    
    [self doHttpPost:SERVER_URL_COMMUNITY_WAITER_EVALUATE_QUERY_WEEK_LIST headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo] parameters:params];
}

- (void)loadMoreDataWithKey:(NSString *)keyOrNil{
    NSDictionary *_config = [super paramDic];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:[CommonUtil formatDateStrStyle:@"yyyyMM"] forKey:@"yearWeek"];
    [params setValue:[_config objectForKey:@"uid"] forKey:@"uid"];
    
    _dataItemName = @"EvaluateEntity";
    [self doHttpPost:SERVER_URL_COMMUNITY_WAITER_EVALUATE_QUERY_WEEK_LIST headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo + 1] parameters:params];
}

- (CGFloat)heightForCellAtRow:(NSIndexPath *)index{
//    EvaluateEntity *item = [self.dataList objectAtIndex:index.row];
//    
//    CGFloat height = [self caculateHeightWithoutPaddingForString:[CommonUtil dealNullObject:item.content] AndFontSize:14.0 AndWitdh:305.0];
//    NSLog(@"计算出回复内容文本高度%f",height);
//    return MAX(71.0, height+36.0);
    return 78;
}

/**展示数据*/
- (void)configCell:(UITableViewCell *)cell atIndex:(NSIndexPath *)index{
    if (self.dataList == nil || self.dataList.count == 0) {
        return;
    }
    // evaluate content insertTime
    EvaluateEntity *item = [self.dataList objectAtIndex:index.row];
    EvaluateTableViewCell *tempCell = (EvaluateTableViewCell *)cell;
    tempCell.backgroundColor = [UIColor whiteColor];
    tempCell.nameLable.text = [CommonUtil dealNullObject:item.userName];
    NSString *stateStr;
    if (item.evaluate) {
        //（0：满意，1：基本满意，2：不满意）
        switch (item.evaluate.intValue) {
            case 0:
                stateStr = @"满意";
                break;
            case 1:
                stateStr = @"基本满意";
                break;
            case 2:
                stateStr = @"不满意";
                break;
            default:
                break;
        }
    }
    tempCell.stateLable.text = stateStr;
    tempCell.timeLable.text =  [CommonUtil formatDateStr:item.insertTime style:@"yyyy-MM-dd HH:mm"];
    //[[@"【" stringByAppendingString:[CommonUtil dealNullObject:item.type]] stringByAppendingString:@"】"];
    NSString *contentStr = [CommonUtil dealNullObject:item.content];
    tempCell.contentLable.text = contentStr;
    tempCell.selectionStyle = UITableViewCellSelectionStyleNone;
    tempCell.myView.layer.borderColor = [CommonUtil stringToColor:@"#C0C0C0"].CGColor;
    
    tempCell.myView.layer.borderWidth =0.5;
    
    tempCell.myView.layer.cornerRadius =1.0;
//    CGFloat height = [self caculateHeightWithoutPaddingForString:contentStr AndFontSize:14.0 AndWitdh:305.0];
//    tempCell.contentLable.frame = CGRectMake(10, CGRectGetMaxY(tempCell.timeLable.frame)+20 , 305, height);
    
   
    
}
-(CGFloat)caculateHeightWithoutPaddingForString:(NSString *)string AndFontSize:(CGFloat)size AndWitdh:(CGFloat)width
{
    if (string == nil || string == (id)[NSNull null]) {
        return 0.0;
    }
    NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:string attributes:@{ NSFontAttributeName:[UIFont systemFontOfSize:size]}];
    CGRect textRect = [attributedText boundingRectWithSize:(CGSize){width, CGFLOAT_MAX} options:NSStringDrawingUsesLineFragmentOrigin context:nil];
    return textRect.size.height;
}

@end
